package com.briup.oagg.facade.web.controller.dataset;

import com.briup.oagg.facade.web.vm.page.Page;
import com.briup.framework.utils.web.Response;
import com.briup.oagg.facade.service.dateset.IReservoirService;
import com.briup.oagg.facade.web.vm.dataset.ReservoirAddVM;
import com.briup.oagg.facade.web.vm.dataset.ReservoirUpdateVM;
import com.briup.oagg.facade.web.vm.dataset.ReservoirVM;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 油气藏信息业务前端控制器
 *
 * @author briup
 */
@Api(tags = "1.4.油气藏管理服务")
@RestController
@RequestMapping("/reservoir")
public class ReservoirsController {

    @Autowired
    private IReservoirService service;

    @ApiOperation(value = "新增油气藏",notes = "通过输入名称、特征描述信息、所属圈闭编号保存信息。输入信息都必填。名称不能重复。")
    @PostMapping
    public Response<String> addReservoirs(@RequestBody ReservoirAddVM reservoirAddVM) {
        service.addReservoirs(reservoirAddVM);
        return Response.success();
    }

    @ApiOperation(value = "修改油气藏",notes = "只能修改描述信息")
    @PutMapping
    public Response<String> updateReservoirs(@RequestBody ReservoirUpdateVM reservoirUpdateVM) {
        service.updateReservoirs(reservoirUpdateVM);
        return Response.success();
    }

    @ApiOperation(value = "删除油气藏",notes = "根据油气藏编号删除对应的油气藏信息")
    @ApiImplicitParams(
            @ApiImplicitParam(dataType = "string", name = "reservoirsId", value = "油气藏id", required = true)
    )
    @DeleteMapping("/{reservoirsId}")
    public Response<String> deleteById(@PathVariable String reservoirsId) {
        service.deleteById(reservoirsId);
        return Response.success();
    }

    @ApiOperation(value = "查询油气藏总数")
    @GetMapping("/count")
    public Response<Integer> count() {
        return Response.success(service.count());
    }

    @ApiOperation(value = "分页查询油气藏",notes = "根据圈闭编号、每页大小和当前页分页显示信息列表")
    @ApiImplicitParams({
            @ApiImplicitParam(dataType = "string", name = "trapId", value = "圈闭编号"),
            @ApiImplicitParam(name = "pageNum", value = "当前页码",defaultValue = "1",required = true,dataTypeClass = Integer.class),
            @ApiImplicitParam(name = "pageSize", value = "每页大小",defaultValue = "5",required = true,dataTypeClass = Integer.class)
    })
    @GetMapping("/page")
    public Response<Page<ReservoirVM>> findByPage(String trapId, Integer pageNum, Integer pageSize) {
        Page<ReservoirVM> page = service.findByPage(trapId, pageNum, pageSize);
        return Response.success(page);
    }
}
